﻿using AutoMapper;
using B.S.Orders.Domain;
using B.S.Orders.ErrorCord;
using B.S.Orders.Read.Api.Application.Commands.DocumentsCommand;
using MediatR;
using SqlSugar;

namespace B.S.Orders.Read.Api.Application.CommandsHander.DocumentsCommandHander
{
    public class ShowDocumentsCommandHander : IRequestHandler<ShowDocumentsCommand, APIResult<List<Documents>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public ShowDocumentsCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<APIResult<List<Documents>>> Handle(ShowDocumentsCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Documents>> result = new APIResult<List<Documents>>();

            var list = await db.Queryable<Documents>()
                                .Where(x => x.Del == false && x.DocumentsId == request.DocumentsId)
                                .ToListAsync();

            result.Data = list;

            result.Code = APIEnum.success;
            result.Msg = "查询成功";

            return await Task.FromResult(result);

        }
    }
}
